import {observable, action, asMap, computed,toJS} from 'mobx';
import {BrowserHrm, Browser,AtSomeone,MapPage,CKRichText, SelectPage, Signature} from 'weaver-mobile-page';
import {Toast} from 'weaver-mobile';
import BaseStore from './BaseStore';
import * as API_REQ from '../apis/form';
import {_} from "../util/pcPublic";
import base from "../util/base";
import * as VariableKeys from "../constants/variableKey";
import {returnSourcePage} from '../util/formUtil';
import * as SignUtil from '../util/SignUtil';
import * as EmSDK from '../util/emSDK';
import remove from 'lodash/remove';
import includes from 'lodash/includes';
import adapter from '../adapter/index';
import {getSecondAuthConfig} from "../apis/secondAuth";
import * as authTypes from "../constants/secondAuthType";
import {openQYSAuth} from "../util/secondAuthUtil";
import {verifyRemark} from "../util/SignUtil";
import {QYSUKeyUtil} from '../util/QYSUkeyUtil';
const CKRichEditor = CKRichText.CKRichEditor;
//流程底部操作store,
export class SignInputStore extends BaseStore {
    //转发参数
    Adapter = adapter;
    @observable fowardSubmitParams = {};
    @observable forwardOperatorDatas = [];
    reqOperators = [];

    @observable isShowIconBtnList = true;

    @observable isurger = false;

    isForbidden = false;
    //路由
    @observable forwardHrmStore = new BrowserHrm.Store({route: '/req', id: 'forward'});
    @observable remarkWfStore = new Browser.Store({route: '/req', id: 'remark16'});
    @observable remarkDocStore = new Browser.Store({route: '/req', id: 'remark37'});
    @observable atUserStore = new AtSomeone.Store({route:'/req',id:'remarkat'});
    @observable positionStore = new MapPage.Store({route:'/req/map'});
    @observable ckStore = new CKRichEditor.Store({ initEndCallback: this.registerRichEditor });
    @observable signatureRoute =new Signature.Store({ route: '/req', id: 'sign' });

    @observable signatureForwardRoute =new Signature.Store({ route: '/req', id: 'signForward' });
    @observable chuanyueWfStore = new SelectPage.Store({route: '/req', id: 'setting/chuanyueSetting'});
    @observable zhuanfaWfStore = new SelectPage.Store({route: '/req', id: 'setting/zhuanfaSetting'});
    @observable replyNoticeInfo = {}; //显示转发接收人批注后提醒我
    @observable isfromButtomEditBtn = false;
 
    //二次验证的参数
    secondAuthStore = null;		//二次验证的store
    secondAuthParams = {};      //二次验证需要的一些参数
    filterRequestAction = null;     //过滤流程操作类型的方法(转发、转办、征询等）

    nowPathName='/req'//当前路由

    tsValue = {}; //暂存变量(ts: temporary storage)
    havetsValue = false;
    @observable fwLimitInfo={
        isopen:"-1",
        choiceoperator:"-1",
    };//是否开启选择节点参与人

     //传阅、转发等选择器选项设置
    @observable moreSetting = {
      selectOptions: [],
      chuanyueChoice: '',//传阅的已选项
      zhuanfaChoice: '',//转发的已选项
      isforwardrights: false,
    }
    selectPassParams = {};
    @observable needRemindInfo = {};
    @observable needRemindTypes = ''; //点击转发、传阅等按钮，弹出面板显示的提醒设置
    @observable notNeedRemind = false;

    //意见征询变量
    @observable inquiryVariate = {
      takOverHours: 0,
      takOverMins: 0,
      isOpenTakOvertime: '0'
    }
    constructor() {
        super();
        this.setForwardOperators = this.setForwardOperators.bind(this);
        this.forwardSubmit = this.forwardSubmit.bind(this);
        this.setForwardParams = this.setForwardParams.bind(this);
        this.hiddenSignInput = this.hiddenSignInput.bind(this);
        this.initAtData = this.initAtData.bind(this);
        this.forwardClear = this.forwardClear.bind(this);
        this.showSignInput = this.showSignInput.bind(this);
        this.saveSignAnnex = this.saveSignAnnex.bind(this);
        this.getShowReplyNotice = this.getShowReplyNotice.bind(this);
        this.setForbidden = this.setForbidden.bind(this);
        this.getFwLimitBrowserSet = this.getFwLimitBrowserSet.bind(this);
        this.deleteDoc = this.deleteDoc.bind(this);
    }

    @computed get isForwad() {
        return this.variableMap.has('forwardvisiable') && this.variableMap.get('forwardvisiable') || false;
    }

    getFwLimitBrowserSet = (fun) =>{
        const { forwardflag = '1', nodeid = '',workflowid = '' } = this.fowardSubmitParams;
        API_REQ.getFwLimitBrowserSet({type : 'canChoiceOperator',wfid:workflowid,nodeid:nodeid,fwtype:forwardflag}).then((data)=>{
            const {isopen = '',choiceoperator = ''} = data;
            this.fwLimitInfo = {isopen,choiceoperator};
            let hideTab8 = (isopen == -1 && choiceoperator== -1)|| (isopen == 1 && choiceoperator != 1);
            if(forwardflag != "3" && !hideTab8){
                this.forwardHrmStore.setState({activeKey:"8",dingStatus:""});
            }else{
                this.forwardHrmStore.setState({activeKey:"1"});
            }
            typeof fun =='function' && fun();
        });
    }
    setForwardOperators(ids = '', operators = []) {
        let forwardOperatorids = [];
        let types  = [];
        operators.map((item)=>{
            const {id,type = 'resource'} = item;
            if(type === 'allResource') return;
            if(type === 'resource') {
                forwardOperatorids.push(id);
            } else {
                types.push(`${type}|${id}`);
            }
        })
        if(types.length > 0) {
            const {forwardflag = '1',workflowid = '',nodeid = '',bdf_wfid = '',beagenter='',f_weaver_belongto_userid='',f_weaver_belongto_usertype=''} = this.fowardSubmitParams;
            const reqParams = {forwardflag:forwardflag,workflowid:workflowid,nodeid:nodeid,bdf_wfid:bdf_wfid,agentorbyagentid:beagenter,f_weaver_belongto_userid,f_weaver_belongto_usertype};
            API_REQ.loadForwardResources({'types':types.join(','),...reqParams}).then((r = []) => {
                const {datas = []} = r;
                datas.map((d = {})=>{
                    const {users = []} = d;
                    users.map((f = {}) => {
                        forwardOperatorids.push(f.id);
                    })
                })
                this.setForwardParams({'field5': forwardOperatorids.join(',')});
                this.forwardOperatorDatas.replace(operators);
            })
        } else {
            this.setForwardParams({'field5': ids});
            this.forwardOperatorDatas.replace(operators);
        }
    }

    @action
    registerRichEditor = () => {
        const { editor } = this.ckStore;
        const remarkKey = this.isForwad ? VariableKeys.FORWARD_SIGN_CONTENT : VariableKeys.SIGN_CONTENT;
        editor.on('blur', () => {
            let updateParams = {};
            updateParams[remarkKey] = this.ckStore.getData();
            this.batchControlVariableMap(updateParams);
        })
    }

    @action('更新转发提交参数')
    setForwardParams(updateParams = {}) {
        this.fowardSubmitParams = {...this.fowardSubmitParams, ...updateParams};
    }

    setSecondAuthParams(params, secondAuthStore, filterRequestAction) {
        this.secondAuthParams = params ? params : null;
        this.secondAuthStore = secondAuthStore ? secondAuthStore : null;
        this.filterRequestAction = filterRequestAction && typeof filterRequestAction == "function" ? filterRequestAction : null;
    }

    getForwardRemark(){
        const {isRichText} = base.wfOperateStore;
        let _forwardremark = "";
        let forwardremark = '';
        if (isRichText) {
            forwardremark = this.ckStore.getData();
        } else {
            forwardremark = this.variableMap.has('forwardremark') ? this.variableMap.get('forwardremark') : '';
        }
        _forwardremark = SignUtil.remarkFilter(forwardremark);
        _forwardremark = SignUtil.appendQuote(_forwardremark);
        return _forwardremark;
    }

    @action('转发提交')
    forwardSubmit(updateParams = {}) {
        const secondAuthStore = this.secondAuthStore;
        const secondAuthParams = this.secondAuthParams;
        const filterRequestAction = this.filterRequestAction;

        this.getForwardRemark();
        let _forwardremark = this.getForwardRemark();

        if (secondAuthStore && secondAuthParams && filterRequestAction) {
            const {workflowid, nodeid, requestid, f_weaver_belongto_userid, f_weaver_belongto_usertype} = secondAuthParams;
            const {isAuthSuccess, isProtectSuccess} = secondAuthStore;
            const $this = this;

            //已验证通过或者已数据保护通过
            if (isAuthSuccess == 1 || isProtectSuccess == 1) {
                const {isEnableAuth, secondAuthType, isEnableProtect, protectType, authKey, qysSignWay = 2} = secondAuthStore;

                if (isProtectSuccess != 1 && isEnableProtect == 1) {      //仍然需要数据保护
                    secondAuthStore.setCallbackFunc(this.forwardSubmit.bind(this));
                    secondAuthStore.setCallbackParam(updateParams);

                    if (protectType == authTypes.CA_AUTH|| (protectType == authTypes.QYS && qysSignWay == 1)) {     //CA数据保护
                        const isProtectDialog = 1;    //1表示打开的是CA数据保护的窗口
                        secondAuthStore.setCAAuthData({isProtectDialog});
                        if((protectType == authTypes.CA_AUTH && secondAuthType == authTypes.QYS && qysSignWay == 1)
                            ||(secondAuthType == authTypes.CA_AUTH && protectType == authTypes.QYS && qysSignWay == 1)){
                            getSecondAuthConfig({workflowid, nodeid, requestid, remark:_forwardremark}).then(data => {
                                const {authKey, sourcestr} = data;
                                secondAuthStore.setCAAuthData({authKey, sourcestr});
                                if (protectType == authTypes.QYS && qysSignWay == 1) {
                                    QYSUKeyUtil.showSignWin(secondAuthStore);
                                } else {
                                    //弹出验证或者数据保护的窗口
                                    secondAuthStore.controlDialogVisible(authTypes.SECOND_AUTH_DIALOG, true);
                                }
                            });
                        }else {
                            if (protectType == authTypes.QYS && qysSignWay == 1) {
                                QYSUKeyUtil.showSignWin(secondAuthStore);
                            } else {
                                //弹出验证或者数据保护的窗口
                                secondAuthStore.controlDialogVisible(authTypes.SECOND_AUTH_DIALOG, true);
                            }
                        }
                        return;
                    } else if (protectType == authTypes.QYS && qysSignWay == 2) {     //契约锁数据保护
                        const isProtectDialog = 1;    //1表示打开的是契约锁数据保护的窗口
                        secondAuthStore.setCAAuthData({isProtectDialog});

                        //弹出契约锁验证或者数据保护的窗口
                        openQYSAuth();
                        return;
                    }
                }

                //能运行到这里，说明已经做完了数据保护
                if (isEnableProtect == 1) {
                    if (protectType == authTypes.CA_AUTH|| (protectType == authTypes.QYS && qysSignWay == 1)) {
                        updateParams = {...updateParams, authKey, isProtectSuccess};
                    }
                }

                //契约锁数据保护或者认证
                if (protectType == authTypes.QYS || secondAuthType == authTypes.QYS) {
                    const {authResult} = secondAuthStore;
                    const {qysSealId, qysSealImg, qysCertDetails} = authResult;
                    updateParams = {...updateParams, qysSealId, qysSealImg, qysCertDetails};
                }

                updateParams = {...updateParams, protectType, qysSignWay, secondAuthType, isAuthSuccess,isEnableProtect};

                secondAuthStore.resetStore();

                //只验证签字意见
                verifyRemark({needCheck:true,needPrompt:false});

                this.forwardSubmit0(updateParams);
            } else {     //没有做过数据验证
                getSecondAuthConfig({workflowid, nodeid, requestid, remark: _forwardremark}).then(data => {
                    const {isEnableAuth = 0, secondAuthType = 0, isEnableProtect = 0, protectType = 0, qysSignWay = 2, authOperations = [], signUrl = ""} = data;
                    const params = {...this.fowardSubmitParams, ...updateParams};
                    const isNeedCheck = this.filterRequestAction(params, secondAuthParams, authOperations) || false;        //是否需要二次验证
                    if (isNeedCheck) {
                        secondAuthStore.setDialogData({isEnableAuth, secondAuthType, isEnableProtect, protectType,qysSignWay, signUrl});
                        //如果开启了数据保护或者数据验证，但是没有不是在EM app上执行操作，就提示
                        if(!secondAuthStore.canDoSecondAuth()){
                            return;
                        }
                        if (isEnableAuth == 1) {        //二次认证
                            let isProtectDialog = 0;

                            //同时是CA认证和数据保护或者契约锁认证和数据保护
                            if (secondAuthType == authTypes.CA_AUTH && isEnableProtect == 1 && protectType == authTypes.CA_AUTH
                                || secondAuthType == authTypes.QYS && isEnableProtect == 1 && protectType == authTypes.QYS) {
                                isProtectDialog = 10;    ////10表示打开的是CA二次认证+ CA数据保护的窗口 或者 契约锁二次认证 + 契约锁数据保护的窗口
                            }
                            secondAuthStore.setCAAuthData({isProtectDialog});

                            if ((secondAuthType == authTypes.CA_AUTH || (isEnableProtect == 1 && protectType == authTypes.CA_AUTH))
                                ||((secondAuthType == authTypes.QYS||(protectType == authTypes.QYS&&isEnableProtect == 1))&& qysSignWay == 1)){
                                const {authKey, sourcestr = Math.random()} = data;
                                secondAuthStore.setCAAuthData({authKey, sourcestr});
                            }

                            //弹出验证或者数据保护的窗口
                            secondAuthStore.setCallbackFunc($this.forwardSubmit.bind(this));
                            secondAuthStore.setCallbackParam(updateParams);

                            if (secondAuthType == authTypes.QYS && qysSignWay == 2) {      //契约锁二次认证或者数据保护
                                openQYSAuth();
                            } else if(secondAuthType == authTypes.QYS && qysSignWay == 1) {
                                QYSUKeyUtil.showSignWin(secondAuthStore);
                            }else{//其他二次认证或者数据保护
                                secondAuthStore.controlDialogVisible(authTypes.SECOND_AUTH_DIALOG, true);
                            }
                        } else {     //没有开启二次认证
                            if (isEnableProtect == 1) {
                                //弹出验证或者数据保护的窗口
                                secondAuthStore.setCallbackFunc($this.forwardSubmit.bind(this));
                                secondAuthStore.setCallbackParam(updateParams);

                                //目前数据保护的方式只有2种：CA保护，契约锁保护
                                if (protectType == authTypes.CA_AUTH||(protectType == authTypes.QYS && qysSignWay == 1)) {       //CA认证的方式
                                    const isProtectDialog = 1;    //1表示打开的是CA数据保护的窗口
                                    const {authKey, sourcestr} = data;
                                    secondAuthStore.setCAAuthData({authKey, sourcestr, isProtectDialog});
                                    if (protectType == authTypes.QYS && qysSignWay == 1) {
                                        QYSUKeyUtil.showSignWin(secondAuthStore);
                                    }else{
                                        secondAuthStore.controlDialogVisible(authTypes.SECOND_AUTH_DIALOG, true);
                                    }
                                } else {     //契约锁保护，也需要打开窗口，让用户选择签章
                                    const isProtectDialog = 1;    //1表示打开的是契约锁数据保护的窗口
                                    secondAuthStore.setCAAuthData({isProtectDialog});
                                    openQYSAuth();
                                }
                            } else {
                                secondAuthStore.resetStore();
                                this.forwardSubmit0(updateParams);
                            }
                        }
                    } else {
                        secondAuthStore.resetStore();
                        this.forwardSubmit0(updateParams);
                    }
                });
            }
        } else {
            this.forwardSubmit0(updateParams);
        }
    }

    @action('转发提交')
    forwardSubmit0(updateParams = {}) {
        if(!this.isForbidden) {
            this.isForbidden = true;
            const {isRichText} = base.wfOperateStore;
            let forwardremark = '';
            if (isRichText) {
                forwardremark = this.ckStore.getData();
            } else {
                forwardremark = this.variableMap.has('forwardremark') ? this.variableMap.get('forwardremark') : '';
            }
            let _forwardremark = SignUtil.remarkFilter(forwardremark);
            _forwardremark = SignUtil.appendQuote(_forwardremark);
            const signInfo = SignUtil.getSignInfoDatas() || {};

            const params = {...this.fowardSubmitParams, ...updateParams,remark: _forwardremark, ...signInfo, ...this.selectPassParams,IsBeForwardAlready: this.selectPassParams.IsBeForwardTodo,
                IsBeForwardSubmitAlready: this.selectPassParams.IsSubmitedOpinion};

            const {forwardflag = '1'} = params;
            base.wfGlobalStore.setLoading(true);
            // const {controllBottomBtnDisable} = base.allStores.wfOperateStore;
            // controllBottomBtnDisable(true);
            API_REQ.forwardSubmit(params).then(data => {
                this.isForbidden = false;
                base.wfGlobalStore.setLoading(false);
                const {success} = data;
                if (!success) {
                    const {msg} = data;
                    Toast.info(msg, 2);
                    try {
                        window.setTimeout(() => {
                            data.needReload && window.wfform.reloadPage();
                        }, 2000);
                    } catch (e) {}
                    return;
                }

                //回调
                let updateParams = {};
                updateParams[VariableKeys.FORWARD_SIGN_CONTENT] = '';
                this.hiddenSignInput(updateParams);
                //重新加载签字意见列表
                if (forwardflag == '1' || forwardflag == '4') {
                    const reloadLogListParams = {pgnumber: 1, atmet: '', maxrequestlogid: 0};
                    const {updateLogParams, activeKey, setState} = base.allStores.wfSignListStore;
                    if (activeKey != '1') setState({activeKey: '1'});
                    updateLogParams(reloadLogListParams, true);

                    // const {lastoperator,lastoperatedate,lastoperatetime} = data;
                    // let updateinfo = {
                    //     lastOperator: lastoperator,
                    //     lastOperateDate: lastoperatedate,
                    //     lastOperateTime: lastoperatetime,
                    // };
                    //base.wfOperateStore.changeSubmitParam(updateinfo);
                } else {
                    returnSourcePage({source : "forwardSubmit"});
                }
                this.forwardClear();
                this.tsValue = {}; // 清空暂存变量值
                //清空转发，传阅设置选项
                this.moreSetting.chuanyueChoice = '';
                this.moreSetting.zhuanfaChoice = '';

                try {
                    window.wfform.changeFieldAttr('field-10', 1);//转发后，密级字段设置为只读
                } catch (e) {}
                // controllBottomBtnDisable(false);

            });
        }
    }

    initAtData() {
        const {requestid} = base.wfGlobalStore.commonParam;
        //避免多次请求
        if(this.reqOperators.length === 0 && requestid > 0) {
            API_REQ.getReqAtUser({requestid}).then((data = {}) => {
                let operators = data.operators || [];
                let reqOperatorIds = [];
                remove(operators,(item)=>{
                    let isInclude = includes(reqOperatorIds,item.id);
                    if(!isInclude) reqOperatorIds.push(item.id);
                    return isInclude;
                });
                this.reqOperators  = operators.slice(0,100);
            })
        }
    }

    @action('转发接收人批注后提醒我')
    getShowReplyNotice = (params)=>{
        API_REQ.getReplyNoticeInfo(params).then(data => {
            this.replyNoticeInfo = data;
            this.setForwardParams({isShowReplyNotice: data.replyNotice});
        })
        this.getSelectInfo(params);
    }
  
      @action('修改意见征询变量值')
      setInquiryVariate = (val = {}) => {
        Object.keys(val).forEach( v => {
          if(this.inquiryVariate.hasOwnProperty(v)) {
            this.inquiryVariate[v] = val[v]
          }
        })
      }
      @action('清理意见征询变量') 
      clearInquiryVariate = () => {
        Object.keys(this.inquiryVariate).forEach( v => {
          this.inquiryVariate[v] = 0;
        })
      }
      //forwardflag = 4 ;传阅 ==1转发
      @action changeChoices = (val, forwardflag) => {
        let arr = val.split(',');
        let passParams = {isChuanyue: 0,
                          isRemind:0,
                          isSubmitSign: 0,
                          IsSubmitedOpinion: 0,
                          IsBeForwardTodo: 0,
                        };
        if( arr.length !== 0 && forwardflag == '4') {
          arr.map(v => {
            if(v == '0') { passParams.isSubmitSign  = 1 }
            if(v == '1') { passParams.isChuanyue = 1 }
            if(v == '2') { passParams.isRemind = 1 }
          })
        } 
        if( arr.length !== 0 && forwardflag == '1') { //待办,归档
          arr.map( v => {
            if(v == '0') { passParams.IsSubmitedOpinion = 1 }
            if(v == '1') { passParams.IsBeForwardTodo = 1 }
          })
        }
        this.selectPassParams = passParams;
        if(forwardflag == '4') {this.moreSetting.chuanyueChoice = val }
        if(forwardflag == '1') {this.moreSetting.zhuanfaChoice = val}
       
      }
  
      @action clearSetStatus = () => {
        this.isformBottomEditBtn =  false;
        this.fowardSubmitParams = {...this.fowardSubmitParams, forwardflag: '', isMulitTak: false};
        this.notNeedRemind = false;
        this.moreSetting.selectOptions = []; //清空选项
        this.fwLimitInfo={isopen:"-1",choiceoperator:'-1'};
      }
  
      @action('暂存变量值') 
      saveKeyValueTemporary = (params={}) => {
        this.havetsValue = true;
        this.tsValue.selectOptions =  this.moreSetting.selectOptions.slice() || [];
        this.tsValue.notNeedRemind = this.notNeedRemind;
        this.tsValue.isformBottomEditBtn = this.isformBottomEditBtn;
        this.tsValue.otherParams = {...this.tsValue.otherParams, ...params};
        this.tsValue.inquiryVariate =  JSON.parse(JSON.stringify(this.inquiryVariate));
      } 
      
      @action('重新设置相关变量值')
      resetKeyValue = () => {
        this.moreSetting.selectOptions = this.tsValue.selectOptions || [];
        this.notNeedRemind  = this.tsValue.notNeedRemind;
        this.isformBottomEditBtn = this.tsValue.isformBottomEditBtn;
        this.setForwardParams(this.tsValue.otherParams);
        if(this.tsValue.inquiryVariate) {
          this.inquiryVariate =  JSON.parse(JSON.stringify(this.tsValue.inquiryVariate));
        } 
      }
  
      @action('清除来自底部编辑按钮点击的标志')
      clearformButtomFlag = () => {
        this.isformBottomEditBtn = false;
      } 
    @action('点击批阅、转发按钮获取选项') 
    getSelectInfo = (params) => {
       const {commonParam}= base.allStores.wfGlobalStore;
       const {requestType, isremark=''} = commonParam;
      const {forwardflag} = this.fowardSubmitParams;
      let arr = [],zfArr=[], zfdefaultChoice = '',cydefaultChoice='';
      API_REQ.getSignInput(params).then(data => {
        this.moreSetting.isforwardrights = data.isforwardrights;
        this.moreSetting.selectOptions = [];
        if(forwardflag == '1') {
          
            const { IsBeForwardTodoShowname = '可转发', IsSubmitedOpinionShowname = '可提交意见', IsSubmitedOpinion='',  IsBeForwardTodo=''} = data; 
            arr = [IsSubmitedOpinionShowname, IsBeForwardTodoShowname]; 
            zfArr = [IsSubmitedOpinion, IsBeForwardTodo];
          
          //设置转发默认选中项 
            let arrtemp = [];
            zfArr.map((item, index) => {
              if(item == '1') {
                arrtemp = [...arrtemp, index];
              }
              zfdefaultChoice = arrtemp.join();
            })
            this.changeChoices(zfdefaultChoice, '1');
        }
        if(forwardflag == '4') {
          const { chuanyueName = '', remindName = '', submitSignName = '', isChuanyue = '', isRemind = '', isSubmitSign = '' } = data.chuanyueInfo;
            arr = [submitSignName, chuanyueName, remindName];
            //设置传阅默认选中项
            let cyArr = [isSubmitSign, isChuanyue, isRemind];
            let arrtemp = [];
            cyArr.map((item, index) => {
              
              if(item == '1') {
                arrtemp = [...arrtemp, index];
              }
              cydefaultChoice = arrtemp.join();
            })
       
            this.changeChoices(cydefaultChoice, '4');
        }
        arr.map((item, index) => {
            this.moreSetting.selectOptions.push({key: index + '', showname: item})
        })
        this.saveKeyValueTemporary(); //暂存转发、传阅接收人权限设置项

      })
      //获取提醒设置信息
      API_REQ.loadRemindInfo({requestid: params.requestid}).then(data => {
          this.needRemindInfo = data;
          this.needRemindTypes = data.value;
      });
    }

    hiddenSignInput(otherParams = {}){
        const updateParams  = {};
        updateParams[VariableKeys.SHOW_SIGN_AREA] = false;
        updateParams[VariableKeys.SHOW_SIGN_BTN] = true;
        updateParams[VariableKeys.FORWARD_VISIABLE] = false;
        updateParams[VariableKeys.SHOW_MORE_FUN] = false;
        updateParams[VariableKeys.SIGN_IMG_UPLOAD] = false;
        updateParams[VariableKeys.SIGN_VOICE_ENTRY]=false;
        updateParams[VariableKeys.CURR_OPERATE_TYPE] = '';
        this.batchControlVariableMap({...updateParams,...otherParams});
        SignUtil.setMetaViewport(true);
        EmSDK.controlBottomBtn(this.nowPathName);
        this.isurger = false;
        this.replyNoticeInfo = {};
    }

    @action
    setNowPathName = (val) => {
        this.nowPathName = val;
    }
    //showSignInput传入的第二个参数表示底部表单意见按钮点击
    showSignInput(otherParams = {}, fromWhichBtn){
        const showSignArea = SignUtil.getVariableMapVal(VariableKeys.SHOW_SIGN_AREA,false);
        if(!showSignArea) {
            const updateParams = {};
            updateParams[VariableKeys.SHOW_SIGN_BTN] = false;
            updateParams[VariableKeys.SHOW_SIGN_AREA] = true;
            this.batchControlVariableMap({...updateParams,...otherParams});
            SignUtil.setMetaViewport(false);
            EmSDK.controlBottomBtn('/req');
        }
        if(fromWhichBtn == 'yijian') this.isformBottomEditBtn = true; //来自底部意见按钮的编辑，面板不显示转发等操作的权限等设置
        if(fromWhichBtn == 'duban') this.notNeedRemind = true; //设置督办不显示提醒设置
    }

    @action
    setShowIconBtnList = (val)=>{
        this.isShowIconBtnList = val;
    }

    //语音、全文批注、手写签批
    saveSignAnnex(type,dataBase64,callback){
        let params  = {type,data:dataBase64};
        API_REQ.saveMobileSignAnnex(params).then((data = {})=>{
            const {fileid = 0,encodeFileid = ''} = data;
            if( fileid > 0) {
                let key =  '';
                let datasrc = '';
                if(type == 1) {
                    key = this.isForwad ? VariableKeys.FORWARD_SIGN_SPEECH_ATTCHMENT_DATAS : VariableKeys.SIGN_SPEECH_ATTCHMENT_DATAS;
                      datasrc =  `data:audio/mp3;base64,${dataBase64}`;
                } else if (type == 2) {//全文批注
                    key = this.isForwad ? VariableKeys.FORWARD_SIGN_FULL_TEXT_ANNOTATION : VariableKeys.SIGN_FULL_TEXT_ANNOTATION;
                    datasrc =  `/weaver/weaver.file.FileDownload?fileid=${encodeFileid}&download=1`;
                } else if (type == 3){//手写签批
                    Toast.hide();
                    key = this.isForwad ? VariableKeys.FORWARD_SIGN_HANDWRITTEN : VariableKeys.SIGN_HANDWRITTEN;
                    datasrc = JSON.parse(dataBase64).allUrls;
                    this.controlVariableMap(key, {fileid,datasrc});//每次上传都是直接替换上一次的，所以不用获取上一次的数据再进行push
                    if(typeof callback == 'function') callback();
                    return; 
                }
                const resourcedatas = SignUtil.getVariableMapVal(key, []);
                resourcedatas.push({fileid,datasrc});
                this.controlVariableMap(key, resourcedatas);
            } else {
                //上传失败
            }
        })
    }

    /**
     * 转发、意见征询、转办提交后清空签字意见数据
     */
    forwardClear(){
        let clearParams  = {};
        clearParams[VariableKeys.FORWARD_SIGN_CONTENT] = '';
        clearParams[VariableKeys.FORWARD_SIGN_FULL_TEXT_ANNOTATION] = [];
        clearParams[VariableKeys.FORWARD_SIGN_HANDWRITTEN] = {};
        clearParams[VariableKeys.FORWARD_SIGN_SPEECH_ATTCHMENT_DATAS] = [];
        clearParams[VariableKeys.FORWARD_REMARK_LOCATION] = {};
        clearParams[VariableKeys.FORWARD_SIGN_IMAGE] = [];
        clearParams[VariableKeys.FORWARD_SIGN_ANNEX_DOC_INFOS] = [];
        clearParams[VariableKeys.FORWARD_SIGN_WF_REPLACE_DATAS] = [];
        clearParams[VariableKeys.FORWARD_SIGN_DOC_REPLACE_DATAS] = [];
        clearParams[VariableKeys.FORWARD_SIGN_REMARK_QUOTE] = [];

        this.fowardSubmitParams = {};
        this.forwardOperatorDatas.replace([]);
        this.batchControlVariableMap(clearParams);
    }

    @action
    setForbidden(val = false) {
        this.isForbidden = val;
    }

    /**
     * 初始化手写签批内容
     */
    initHandWritingData = () => {
        const { markInfo={} } = base.wfOperateStore;
        const { remarkInfo={} } = markInfo; 
        const { signHandWritten={},signHandWrittenColor="#010102", signHandWrittenBrush="xs" } = remarkInfo;
        const{datas="{}", urls=[], fileid=0, allUrls="", modeType="{}",url} = signHandWritten;
        this.signatureRoute.setState({color: signHandWrittenColor, brush:signHandWrittenBrush});
        let datasrc=allUrls;
        if(url){//有url说明上一次保存的数据是客户端的
            datasrc = url;
            this.controlVariableMap(VariableKeys.SIGN_HANDWRITTEN+"_datasAndUrls", {client:"em",url})
        }else{
            let isPc=(modeType==1||modeType==0);
            let _modeType={}
            if(isPc){
                _modeType={brush:"xs",color:signHandWrittenColor,modeType:modeType}
            }else{
                _modeType=JSON.parse(modeType);
            }
            this.controlVariableMap(VariableKeys.SIGN_HANDWRITTEN+"_datasAndUrls", {urls,datas:JSON.parse(datas), ismobile:true, modeType:_modeType, signHandWrittenColor, signHandWrittenBrush})
        }
        fileid > 0 && this.controlVariableMap(VariableKeys.SIGN_HANDWRITTEN, {fileid,datasrc});//每次上传都是直接替换上一次的，所以不用获取上一次的数据再进行push

    }

    @action('根据id，删除文档') 
    deleteDoc = (params) => {
        API_REQ.deleteDoc(params).then(data => {

        })
    }
}